package main

import (
	"fmt"
	"sort"
)

func main() {
	//fmt.Println(eraseOverlapIntervals([][]int{{1, 2}, {2, 3}, {3, 4}, {1, 3}}))
	fmt.Println(eraseOverlapIntervals([][]int{{1, 100}, {11, 22}, {1, 11}, {2, 12}}))
}

// {1, 11} {2, 12} {11, 22} {1, 100}
func eraseOverlapIntervals(intervals [][]int) (res int) {
	sort.Slice(intervals, func(i, j int) bool {
		return intervals[i][1] < intervals[j][1]
	})
	curMax := intervals[0][1]
	for i := 1; i < len(intervals); i++ {
		if intervals[i][0] >= curMax {
			curMax = intervals[i][1]
		} else {
			res++
		}
	}
	return
}
